import config from "@/config"
import http from "@/utils/request"


// 审核规则 -- 工作流
export default {
  getWorkflowList: {
    url: `${config.API_URL}/workflow/pageList`,
    name: "获取工作流列表",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getWorkflowListByType: {
    url: `${config.API_URL}/workflow/list`,
    name: "根据流程类型获取工作流",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getWorkflowListById: {
    url: `${config.API_URL}/workflow/one`,
    name: "根据id获取工作流",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addtWorkflow: {
    url: `${config.API_URL}/workflow/addWorkflow`,
    name: "添加工作流",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updateWorkflow: {
    url: `${config.API_URL}/workflow/updateWorkflow`,
    name: "修改工作流",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteWorkflow: {
    url: `${config.API_URL}/workflow/deleteOrDeleteBatch`,
    name: "删除工作流",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  // 审核配置中 选择主管 -- 根据部门id获取主管信息  除了setType = 3（选择部门） 以外
  getLeaderById: {
    url: `${config.API_URL}/position/oneLevel`,
    name: "根据部门id获取主管信息",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  //  审核配置中 -- 选择部门时  
  getLeaderByDeptId: {
    url: `${config.API_URL}/position/chooseDepartment`,
    name: "根据所选的部门ID获取主管信息",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  checkUserIsAudit: {
    url: `${config.API_URL}/examine/isAudit`,
    name: "检测当前用户是否有审核的权限",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  // 提交审批
  handleAudit: {
    url: `${config.API_URL}/examine/audit`,
    name: "审批操作",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  handleReverseAudit: {
    url: `${config.API_URL}/examine/antiAudit`,
    name: "反审批",
    post: function (param) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  handleApply: {
    url: `${config.API_URL}/examine/addOperation`,
    name: "申请修改",//申请重新审批
    post: function (param) {
      return new Promise((resolve, reject) => {
        http.post(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getLog: {
    url: `${config.API_URL}/modifyLog/modLogList`,
    name: "获取申请修改日志",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  addSgin: {
    url: `${config.API_URL}/examine/addSign`,
    name: "添加加签",
    post: function (param) {
      return new Promise((resolve, reject) => {
        http.post(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
}
